<?php

include_once 'common.php';
include_once 'database.php';

function getListOfProjectsForUser(){
	//Get user from session
	$strUsername = $_SESSION['user'];
	$intUserId = getUserIdFromUsername($strUsername);
	
	//Get project for user
	$arrUserProjects = array();
	
	$dbResult = mysql_query("SELECT * FROM project WHERE account_id=$intUserId")
		or die("Problem reading table: " . mysql_error());
	
	while($row = mysql_fetch_array($dbResult)){
		$objProject = array();
		$objProject['project_id'] = $row['project_id'];
		$objProject['project_name'] = $row['project_name'];
		
		array_push($arrUserProjects, $objProject);
	}
	
	return $arrUserProjects;
}


function getListOfTasksForUser(){
	//Get user from session
	$strUsername = $_SESSION['user'];
	$intUserId = getUserIdFromUsername($strUsername);
	//Current date
	$dateCurrentDate = date(MYSQL_DATEFORMAT);
	
	//Get current user tasks
	$arrUserTasks = array();
	
	$strTaskQuery = "SELECT s.story_id, t.task_name FROM " .
					"project p " .
					"JOIN iteration i ON i.project_id = p.project_id " .
					"JOIN story s ON i.iteration_id = s.iteration_id " .
					"JOIN task t ON s.story_id = t.story_id " .
					"WHERE p.account_id = $intUserId AND '$dateCurrentDate' BETWEEN i.start_date AND i.end_date";
	$dbResult = mysql_query($strTaskQuery)
		or die("Problem reading table: " . mysql_error());
	
	while($row = mysql_fetch_array($dbResult)){
		$objTask = array();
		$objTask['story_id'] = $row['story_id'];
		$objTask['task_name'] = $row['task_name'];
	
		array_push($arrUserTasks, $objTask);
	}
	
	
	return $arrUserTasks;
}
